package com.iwith.dongmoon.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;

import com.iwith.dongmoon.util.SessionManager;

public class MainTabView extends TabActivity implements OnClickListener, OnTabChangeListener {
	private ImageView title;
	private TabHost mTabHost;
	private final String [] TAB_ID = {"FIND", "NEWS", "BOARD", "INTERESTS", "INFO"};
	private final String [] TAB_NAME = {"동문찾기", "동문소식", "자유게시판", "관심동문", "개인정보"};
	private final Integer [] TAB_IMAGE = { R.drawable.tab_search, R.drawable.tab_news, R.drawable.tab_group, R.drawable.tab_favorite, R.drawable.tab_profile };
	private Integer tabPosition;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// TODO Auto-generated method stub
		setContentView(R.layout.tabview);
		
		
		final Intent [] TAB_INTENT = { new Intent(MainTabView.this, Tab_FindActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
				   new Intent(MainTabView.this, Tab_NewsBoardActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
				   new Intent(MainTabView.this, Tab_FreeBoardActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
				   new Intent(MainTabView.this, Tab_InterestsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
				   new Intent(MainTabView.this, Tab_InfoActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) };
		
		
		mTabHost=getTabHost();
		for(int i = 0; i < TAB_ID.length; i++)
		{
			mTabHost.addTab(mTabHost.newTabSpec(TAB_ID[i]).setIndicator(TAB_NAME[i]).setContent(TAB_INTENT[i]));
			mTabHost.getTabWidget().getChildAt(i).setBackgroundResource(TAB_IMAGE[i]);
		}
		
		title=(ImageView)findViewById(R.id.title);
		title.setOnClickListener(this);
		
		Initialize();
	}
	
	private void Initialize(){
		if(getIntent().getExtras()!=null){
			tabPosition=getIntent().getExtras().getInt("tab_position");
			
			if(tabPosition<TAB_ID.length){
				mTabHost.setCurrentTab(tabPosition);
			} else {
				//Toast.makeText(this, "준비중인 메뉴입니다.", 0).show();
			}
		} else {
			tabPosition = 0;
		}
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.getId()==title.getId()){
			Intent intent=new Intent(this, MainIconView.class);
			intent.putExtra("flag", true);
			//intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
			startActivity(intent);
		}
	}

	public void onTabChanged(String tabId) {
		// TODO Auto-generated method stub
		tabPosition=getIntent().getExtras().getInt("tab_position");
	}
}


